package cn.tedu.cn.tedu.homework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author :Colin
 * @version 创建时间: 2021/7/3 9:16
 */
public class CreateUser {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");

        String url="jdbc:mysql://localhost:3306/colinbase?characterEncoding=utf8";
        Connection conn = DriverManager.getConnection(url, "root", "root");
        Statement st = conn.createStatement();
        String sql1="create table user(id int primary key auto_increment,name varchar(20) not null," +
                "password varchar(20) not null)";
        //int i1 = st.executeUpdate(sql1);
        String name = signUpName();
        String password = signUpPassword();
        //String sql2="insert into user values(null,'name1','password1'),(null,'name2','password2'),(null,'name3','password3')";
        String sql2="insert into user values(null,"+"'"+name+"',"+"'"+password+"')";
        int i2 = st.executeUpdate(sql2);
        System.out.println("succeed");
        st.close();
        conn.close();

    }

    private static String signUpPassword() {
        System.out.println("请输入注册密码");
        String password=new Scanner(System.in).nextLine();
        return password;
    }

    private static String signUpName() {
        System.out.println("请输入注册用户名");
        String name=new Scanner(System.in).nextLine();
        return name;
    }
}
